package com.xl.activiti.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.impl.asyncexecutor.ManagedAsyncJobExecutor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 配置Activiti异步任务自动启动
 * @author zhongwm
 */
@Slf4j
@Component
public class ActivitiCommandLineRunner implements CommandLineRunner {

    private final ProcessEngine processEngine;

    public ActivitiCommandLineRunner(ProcessEngine processEngine) {
        this.processEngine = processEngine;
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("-------Activiti CommandLineRunner-------");
        processEngine.getProcessEngineConfiguration()
                //.setAsyncExecutor(new ManagedAsyncJobExecutor())
                .setAsyncExecutorActivate(true);
        processEngine.getProcessEngineConfiguration().getAsyncExecutor().start();

        //processEngine.getProcessEngineConfiguration().getAsyncExecutor()
        log.info("AsyncExecutor isActive:{}", processEngine.getProcessEngineConfiguration().getAsyncExecutor().isActive());
        log.info("AsyncExecutor isAutoActivate:{}", processEngine.getProcessEngineConfiguration().getAsyncExecutor().isAutoActivate());
    }
}
